import { ref } from 'vue';
import dayjs from 'dayjs';
import { useAuthStore } from '@/store/modules/auth';

let topFormModel;

function getTotalSetNum() {
  topFormModel.value.totalSet =
    Number(topFormModel.value.kailuSet) +
    Number(topFormModel.value.duanluSet) +
    Number(topFormModel.value.buyouSet) +
    Number(topFormModel.value.kailuSetUseless) +
    Number(topFormModel.value.duanluSetUseless) +
    Number(topFormModel.value.holeBlockSetUseless) +
    Number(topFormModel.value.neiduanSetUseless) +
    Number(topFormModel.value.neikaiSetUseless) +
    Number(topFormModel.value.otherSetUseless);
}

function getTotalPcsNum() {
  topFormModel.value.totalPcs =
    Number(topFormModel.value.kailuPcs) +
    Number(topFormModel.value.duanluPcs) +
    Number(topFormModel.value.buyouPcs) +
    Number(topFormModel.value.kailuPcsUseless) +
    Number(topFormModel.value.duanluPcsUseless) +
    Number(topFormModel.value.holeBlockPcsUseless) +
    Number(topFormModel.value.neiduanPcsUseless) +
    Number(topFormModel.value.neikaiPcsUseless) +
    Number(topFormModel.value.otherPcsUseless);
}

const authStore = useAuthStore();
export default {
  url: '/qms/electricalTest/singleProdRepair/list',
  addUrl: '/qms/electricalTest/singleProdRepair/add',
  editUrl: '/qms/electricalTest/singleProdRepair/update',
  delUrl: '/qms/electricalTest/singleProdRepair/deleteBatch',
  searchFormList: [
    {
      type: 'input',
      key: 'moduleNo',
      label: '生产型号',
      placeholder: '请输入生产型号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'select',
      key: 'state',
      label: '审核状态',
      placeholder: '请选择审核状态',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4,
      selectOptions: [
        {
          value: '0',
          label: '待领班审核'
        },
        {
          value: '1',
          label: '待修改'
        },
        {
          value: '2',
          label: '待主管审核'
        },
        {
          value: '3',
          label: '审核完成'
        }
      ]
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'dateRangePicker',
      key: 'time',
      label: '时间',
      showTime: true,
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 6
    }
  ],
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'moduleNo',
      dataIndex: 'moduleNo',
      title: '生产型号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'state',
      dataIndex: 'state',
      title: '状态',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['待领班审核', '待修改', '待主管审核', '审核完成'][record.state];
      }
    },
    {
      key: 'modifyTime',
      dataIndex: 'modifyTime',
      title: '时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'shiftType',
      dataIndex: 'shiftType',
      title: '班别',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['白班', '夜班'][record.shiftType];
      }
    },
    {
      key: 'kailuSet',
      dataIndex: 'kailuSet',
      title: '开路set',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'kailuPcs',
      dataIndex: 'kailuPcs',
      title: '开路pcs',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'duanluSet',
      dataIndex: 'duanluSet',
      title: '短路set',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'duanluPcs',
      dataIndex: 'duanluPcs',
      title: '短路pcs',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'buyouSet',
      dataIndex: 'buyouSet',
      title: '补油set',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'buyouPcs',
      dataIndex: 'buyouPcs',
      title: '补油pcs',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'kailuSetUseless',
      dataIndex: 'kailuSetUseless',
      title: '开路set报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'kailuPcsUseless',
      dataIndex: 'kailuPcsUseless',
      title: '开路pcs报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'duanluSetUseless',
      dataIndex: 'duanluSetUseless',
      title: '短路set报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'duanluPcsUseless',
      dataIndex: 'duanluPcsUseless',
      title: '短路pcs报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'holeBlockSetUseless',
      dataIndex: 'holeBlockSetUseless',
      title: '孔不通set报废',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'holeBlockPcsUseless',
      dataIndex: 'holeBlockPcsUseless',
      title: '孔不通pcs报废',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'neiduanSetUseless',
      dataIndex: 'neiduanSetUseless',
      title: '内短set报废',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'neiduanPcsUseless',
      dataIndex: 'neiduanPcsUseless',
      title: '内短pcs报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'neikaiSetUseless',
      dataIndex: 'neikaiSetUseless',
      title: '内开set报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'neikaiPcsUseless',
      dataIndex: 'neikaiPcsUseless',
      title: '内开pcs报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'otherSetUseless',
      dataIndex: 'otherSetUseless',
      title: '其他set报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'otherPcsUseless',
      dataIndex: 'otherPcsUseless',
      title: '其他pcs报废',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'totalSet',
      dataIndex: 'totalSet',
      title: '总计set',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'totalPcs',
      dataIndex: 'totalPcs',
      title: '总计pcs',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foreman',
      dataIndex: 'foreman',
      title: '领班审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foremanTime',
      dataIndex: 'foremanTime',
      title: '领班审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examiner',
      dataIndex: 'examiner',
      title: '主管审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '主管审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '创建时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],
  searchParam: ref({
    moduleNo: null,
    state: null,
    time: null
  }),
  scroll: { x: 2500, y: 'auto' },
  formId: '84',

  topFormList: [
    // 用于获取model
    {
      type: 'getModel',
      hidden: true,
      handle(topModel) {
        topFormModel = topModel;
      }
    },
    {
      type: 'input',
      key: 'moduleNo',
      label: '生产型号',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'datePicker',
      key: 'modifyTime',
      label: '录入时间',
      span: 8,
      defaultValue: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'),
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showTime: true
    },
    {
      type: 'radio',
      key: 'shiftType',
      label: '班别',
      span: 6,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      defaultValue: '0',
      selectOptions: [
        {
          label: '白班',
          value: '0'
        },
        {
          label: '夜班',
          value: '1'
        }
      ]
    },
    {
      type: 'input',
      key: 'kailuSet',
      label: '开路set',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'kailuPcs',
      label: '开路pcs',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'duanluSet',
      label: '短路set',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'duanluPcs',
      label: '短路pcs',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'buyouSet',
      label: '补油set',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'buyouPcs',
      label: '补油pcs',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'kailuSetUseless',
      label: '开路set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },

    {
      type: 'input',
      key: 'kailuPcsUseless',
      label: '开路pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'duanluSetUseless',
      label: '短路set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'duanluPcsUseless',
      label: '短路pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'holeBlockSetUseless',
      label: '孔不通set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'holeBlockPcsUseless',
      label: '孔不通pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'neiduanSetUseless',
      label: '内短set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'neiduanPcsUseless',
      label: '内短pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'neikaiSetUseless',
      label: '内开set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'neikaiPcsUseless',
      label: '内开pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalPcsNum();
      }
    },
    {
      type: 'input',
      key: 'otherSetUseless',
      label: '其他set报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      change: () => {
        getTotalSetNum();
      }
    },
    {
      type: 'input',
      key: 'otherPcsUseless',
      label: '其他pcs报废',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'totalSet',
      label: '总计set',
      span: 8,
      disabled: true
    },
    {
      type: 'input',
      key: 'totalPcs',
      label: '总计pcs',
      span: 8,
      disabled: true
    },
    {
      type: 'textarea',
      key: 'result',
      label: '处理结果',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    }
  ],
  bottomList: [
    {
      type: 'input',
      key: 'operator',
      label: '操作员',
      defaultValue: authStore.userInfo.user.nickName || authStore.userInfo.user.userName,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      span: 8
    },
    {
      type: 'input',
      key: 'foreman',
      label: '领班审核',
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'examiner',
      label: '主管审核',
      disabled: true,
      span: 8
    }
  ],
  modalHeight: '90vh',
  editMethod: 'put'
};
